import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 解决导航栏或者底部导航tabBar中的vue-router在3.0版本以上频繁点击菜单报错的问题。
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/front',
    name: 'Front',
    component: () => import('../views/Front.vue'),
    children: [
      { path: 'home', name: 'Home', meta: { name: '智能分析(同步)' }, component: () => import('../views/front/Home') },
      { path: 'homeAsync', name: 'HomeAsync', meta: { name: '智能分析(异步)' }, component: () => import('../views/front/HomeAsync') },
      { path: 'homeMQ', name: 'HomeMQ', meta: { name: '智能分析(MQ)' }, component: () => import('../views/front/HomeMQ') },
      { path: 'myChart', name: 'myChart', meta: { name: '智能分析' }, component: () => import('../views/front/MyChart.vue') },
      { path: 'person', name: 'Person', meta: { name: '个人信息' }, component: () => import('../views/front/Person') },
      { path: 'technology', name: 'Technology', meta: { name: '技术栈' }, component: () => import('../views/front/Technology') },
    ]
  },
  { path: '/login', name: 'Login', meta: { name: '登录' }, component: () => import('../views/Login.vue') },
  { path: '/register', name: 'Register', meta: { name: '注册' }, component: () => import('../views/Register.vue') },
  { path: '*', name: 'NotFound', meta: { name: '无法访问' }, component: () => import('../views/404.vue') },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
